{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3] <class 'list'>\n"
     ]
    }
   ],
   "source": [
    "list = [1, 2, 3]\n",
    "print(list, type(list))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "整个list： ['bijingrui', 23, 99.99, [0, 1]]\n",
      "0号元素： bijingrui\n",
      "最后一个元素 [0, 1]\n"
     ]
    }
   ],
   "source": [
    "# list是具有顺序的一个列表，元素并不需要同一类型\n",
    "list = ['bijingrui', 23, 99.99, [0, 1]]\n",
    "print('整个list：', list)\n",
    "print('0号元素：', list[0])\n",
    "print('最后一个元素', list[-1]) # 0的前面一个，自然就是最后一个"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "bjr\n",
      "['0', '1', '2', '3', '4']\n"
     ]
    }
   ],
   "source": [
    "list[0] = 'bjr' # 修改一个元素\n",
    "print(list[0])\n",
    "\n",
    "list = ['0', '1', '2', '3', '4'] # 修改整个list\n",
    "print(list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['1', '2']"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list[1:3] # 代表 -- [1,3)      3取不到"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['0', '1', '2', '3']"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list[:4]  # 从开始到index=4，   代表-- [0,4)    4取不到"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['3', '4']"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list[3:] # 从3到最后一个元素"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['0', '2']"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list[0:4:2] # a:b:c 从a到b，每c个元素取一个"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4, 5, 6]\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "# 两个list合并, 元素是否在list内\n",
    "list1 = [1, 2, 3]\n",
    "list2 = [4, 5 ,6]\n",
    "list3 = list1 + list2\n",
    "print(list3)\n",
    "print(9 in list3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6\n",
      "0\n",
      "6\n",
      "1\n",
      "['1', '2', '3', '4']\n"
     ]
    }
   ],
   "source": [
    "# len操作, max min 操作,del 操作\n",
    "print(len(list3))\n",
    "print(len([]))\n",
    "\n",
    "print(max(list3))\n",
    "print(min(list3))\n",
    "\n",
    "del(list[0])\n",
    "print(list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['1', '2', '3', '4', '5']\n",
      "['1', '2', '3', '4', '5', [7, 99, 100]]\n"
     ]
    }
   ],
   "source": [
    "list.append('5') # 在后面追加一个元素\n",
    "print(list)\n",
    "list.append([7, 99, 100])\n",
    "print(list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[5, 4, 3, 2, 1]\n",
      "[99, 150, 365, 3389, 5454, 9596]\n",
      "[9596, 5454, 3389, 365, 150, 99]\n",
      "不影响本身的排序：------\n",
      "[99, 365, 150, 9596, 5454, 3389]\n",
      "[99, 150, 365, 3389, 5454, 9596]\n"
     ]
    }
   ],
   "source": [
    "# 倒置， 排序\n",
    "list = [1, 2, 3, 4, 5]\n",
    "list.reverse()\n",
    "print(list)\n",
    "\n",
    "list = [99, 365, 150, 9596, 5454, 3389]\n",
    "list.sort() # 从小到大排序\n",
    "print(list)\n",
    "\n",
    "list.sort(reverse = True) # 反向排序\n",
    "print(list)\n",
    "\n",
    "print('不影响本身的排序：------')\n",
    "list = [99, 365, 150, 9596, 5454, 3389]\n",
    "new_list = sorted(list)\n",
    "print(list)\n",
    "print(new_list)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
